package cn.dankal.flyaudio.activity.search.adapter;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.dankal.business.pojo.HotSearchBean;
import cn.dankal.flyaudio.R;

/**
 * @author ricky
 * @date 2018/8/15 0015
 */
public class HotSearchAdapter extends RecyclerView.Adapter<HotSearchAdapter.ViewHolder> {

    @BindView(R.id.tv_hot_goods_name)
    TextView tvHotGoodsName;
    private List<HotSearchBean> hotGoodsList;
    private Context mContext;
    private View.OnClickListener onClickListener;


    public HotSearchAdapter(Context context, List<HotSearchBean> hotGoodsList, View.OnClickListener onClickListener) {

        mContext = context;
        this.hotGoodsList = hotGoodsList;
        this.onClickListener=onClickListener;


    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.rv_item_hot_search, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        holder.tvHotGoodsName.setText(hotGoodsList.get(position).getTitle());
        holder.tvHotGoodsName.setOnClickListener(onClickListener);

    }


    @Override
    public int getItemCount() {
        return hotGoodsList == null ? 0 : hotGoodsList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_hot_goods_name)
        TextView tvHotGoodsName;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
